<template>
  <div class="category-management">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1 class="page-title">分类管理</h1>
        <p class="page-description">管理商品分类信息</p>
      </div>
      <div class="header-actions">
        <button class="btn btn-success" @click="showAddModal">
          <i class="fas fa-plus"></i>
          添加分类
        </button>
        <button class="btn btn-primary" @click="refreshCategories">
          <i class="fas fa-refresh"></i>
          刷新
        </button>
      </div>
    </div>

    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="search-input-wrapper">
        <i class="fas fa-search search-icon"></i>
        <input
          v-model="searchQuery"
          type="text"
          placeholder="搜索分类名称..."
          class="search-input"
        />
        <button
          v-if="searchQuery"
          class="clear-search"
          @click="clearSearch"
        >
          <i class="fas fa-times"></i>
        </button>
      </div>
    </div>

    <!-- 悬浮批量操作按钮 -->
    <div v-if="selectedCategories.length > 0" class="floating-batch-actions">
      <div class="batch-main">
      <div class="batch-info">
          <span class="selected-count">{{ selectedCategories.length }}</span>
          <span class="selected-text">已选择</span>
      </div>
      <div class="batch-buttons">
          <button @click="showBatchMenu = !showBatchMenu" class="batch-toggle-btn" :class="{ active: showBatchMenu }">
            <i class="fas" :class="showBatchMenu ? 'fa-times' : 'fa-cog'"></i>
          </button>
      </div>
    </div>

      <!-- 批量操作菜单 -->
      <div v-if="showBatchMenu" class="batch-menu">
        <div class="batch-menu-header">
          <h4>批量操作</h4>
        </div>
        <div class="batch-menu-content">
          <div class="batch-action-group">
            <label class="action-label">危险操作</label>
            <div class="action-row">
              <button @click="batchDeleteCategories" class="btn btn-danger btn-sm btn-full">
                <i class="fas fa-trash"></i>
                批量删除分类
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 分类列表 -->
    <div class="categories-section">
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <span>加载分类数据中...</span>
      </div>
      
      <div v-else-if="filteredCategories.length === 0" class="empty-state">
        <i class="fas fa-tags"></i>
        <h3>{{ searchQuery ? '未找到匹配的分类' : '暂无分类数据' }}</h3>
        <p>{{ searchQuery ? '请尝试调整搜索条件' : '点击添加分类按钮创建第一个分类' }}</p>
      </div>
      
      <div v-else class="categories-table-container">
        <table class="categories-table">
          <thead>
            <tr>
              <th class="checkbox-column">
                <input
                  type="checkbox"
                  :checked="isAllSelected"
                  @change="toggleSelectAll"
                  class="batch-checkbox"
                />
              </th>
              <th>分类信息</th>
              <th>父分类</th>
              <th>描述</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="category in paginatedCategories"
              :key="category.categoryId"
              class="category-row"
            >
              <td class="checkbox-column">
                <input
                  type="checkbox"
                  :value="category.categoryId"
                  v-model="selectedCategories"
                  class="batch-checkbox"
                />
              </td>
              
              <td class="category-info-cell">
                <div class="category-icon">
                  <i class="fas fa-tag"></i>
                </div>
                <div class="category-details">
                  <div class="category-name">{{ category.categoryName }}</div>
                  <div class="category-id">ID: {{ category.categoryId }}</div>
                </div>
              </td>
              
              <td class="parent-cell">
                <span v-if="category.parentId">
                  {{ getCategoryName(category.parentId) }}
                </span>
                <span v-else class="no-parent">顶级分类</span>
              </td>
              
              <td class="description-cell">
                <div class="description-text">
                  {{ category.description || '-' }}
                </div>
              </td>
              
              <td class="date-cell">
                {{ formatDate(category.createdAt) }}
              </td>
              
              <td class="actions-cell">
                <div class="action-buttons">
                  <button
                    class="btn btn-sm btn-info"
                    @click="editCategory(category)"
                    title="编辑分类"
                  >
                    <i class="fas fa-edit"></i>
                  </button>
                  <button
                    class="btn btn-sm btn-danger"
                    @click="confirmDeleteCategory(category)"
                    title="删除分类"
                    :disabled="deletingCategoryId === category.categoryId"
                  >
                    <i
                      class="fas"
                      :class="deletingCategoryId === category.categoryId ? 'fa-spinner fa-spin' : 'fa-trash'"
                    ></i>
                  </button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      
      <!-- 分页 -->
      <div v-if="totalPages > 1" class="pagination-container">
        <div class="pagination-info">
          显示 {{ (currentPage - 1) * pageSize + 1 }} - {{ Math.min(currentPage * pageSize, filteredCategories.length) }} 
          共 {{ filteredCategories.length }} 条记录
        </div>
        <div class="pagination-controls">
          <button
            class="btn btn-sm btn-secondary"
            @click="goToPage(currentPage - 1)"
            :disabled="currentPage === 1"
          >
            <i class="fas fa-chevron-left"></i>
          </button>
          
          <div class="page-numbers">
            <button
              v-for="page in visiblePages"
              :key="page"
              class="btn btn-sm"
              :class="page === currentPage ? 'btn-primary' : 'btn-secondary'"
              @click="goToPage(page)"
            >
              {{ page }}
            </button>
          </div>
          
          <button
            class="btn btn-sm btn-secondary"
            @click="goToPage(currentPage + 1)"
            :disabled="currentPage === totalPages"
          >
            <i class="fas fa-chevron-right"></i>
          </button>
        </div>
      </div>
    </div>

    <!-- 添加/编辑分类模态框 -->
    <div v-if="showCategoryModal" class="modal-overlay" @click="closeCategoryModal">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>{{ isEditing ? '编辑分类' : '添加分类' }}</h3>
          <button class="modal-close" @click="closeCategoryModal">
            <i class="fas fa-times"></i>
          </button>
        </div>
        
        <form @submit.prevent="handleSubmit" class="modal-body">
          <div class="form-group">
            <label class="form-label">分类名称 <span class="required">*</span></label>
            <input
              v-model="categoryForm.categoryName"
              type="text"
              class="form-input"
              :class="{ 'error': errors.categoryName }"
              placeholder="请输入分类名称"
              @blur="validateCategoryName"
            />
            <span v-if="errors.categoryName" class="error-text">{{ errors.categoryName }}</span>
          </div>
          
          <div class="form-group">
            <label class="form-label">父分类</label>
            <select
              v-model="categoryForm.parentId"
              class="form-select"
            >
              <option value="">选择父分类（可选）</option>
              <option
                v-for="category in availableParentCategories"
                :key="category.categoryId"
                :value="category.categoryId"
              >
                {{ category.categoryName }}
              </option>
            </select>
          </div>
          
          <div class="form-group">
            <label class="form-label">描述</label>
            <textarea
            v-model="categoryForm.description" 
              class="form-textarea"
              placeholder="请输入分类描述（可选）"
              rows="3"
            ></textarea>
          </div>
        </form>
        
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary"
            @click="closeCategoryModal"
          >
            取消
          </button>
          <button
            type="button"
            class="btn btn-primary"
            @click="handleSubmit"
            :disabled="submitting || !isFormValid"
          >
            <i v-if="submitting" class="fas fa-spinner fa-spin"></i>
            {{ submitting ? '保存中...' : (isEditing ? '更新' : '添加') }}
          </button>
        </div>
      </div>
    </div>
    
    <!-- 删除确认模态框 -->
    <div v-if="showDeleteModal" class="modal-overlay" @click="showDeleteModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>确认删除</h3>
          <button class="modal-close" @click="showDeleteModal = false">
            <i class="fas fa-times"></i>
          </button>
      </div>
        
        <div class="modal-body">
          <p>您确定要删除分类 <strong>"{{ categoryToDelete?.categoryName }}"</strong> 吗？</p>
          <p class="warning-text">此操作不可撤销，请谨慎操作。</p>
        </div>
        
        <div class="modal-footer">
          <button
            class="btn btn-secondary"
            @click="showDeleteModal = false"
          >
            取消
          </button>
          <button
            class="btn btn-danger"
            @click="deleteCategory"
            :disabled="deletingCategoryId === categoryToDelete?.categoryId"
          >
            <i
              class="fas"
              :class="deletingCategoryId === categoryToDelete?.categoryId ? 'fa-spinner fa-spin' : 'fa-trash'"
            ></i>
            确认删除
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, computed, reactive, onMounted, watch } from 'vue'
import { categoryAPI } from '@/api'

export default {
  name: 'CategoryManagement',
  setup() {
    // 响应式数据
    const categories = ref([])
    const loading = ref(false)
    const searchQuery = ref('')
    const currentPage = ref(1)
    const pageSize = ref(10)
    const showCategoryModal = ref(false)
    const showDeleteModal = ref(false)
    const isEditing = ref(false)
    const submitting = ref(false)
    const deletingCategoryId = ref(null)
    const categoryToDelete = ref(null)
    const selectedCategories = ref([])
    const isAllSelected = ref(false)
    const showBatchMenu = ref(false)

    const categoryForm = reactive({
      categoryId: null,
      categoryName: '',
      parentId: '',
      description: ''
    })

    const errors = reactive({
      categoryName: ''
    })
    
    // 计算属性
    const filteredCategories = computed(() => {
      if (!searchQuery.value) return categories.value
      
      const query = searchQuery.value.toLowerCase()
      return categories.value.filter(category => 
        category.categoryName?.toLowerCase().includes(query)
      )
    })

    const totalPages = computed(() => {
      return Math.ceil(filteredCategories.value.length / pageSize.value)
    })
    
    const paginatedCategories = computed(() => {
      const start = (currentPage.value - 1) * pageSize.value
      const end = start + pageSize.value
      return filteredCategories.value.slice(start, end)
    })

    const visiblePages = computed(() => {
      const pages = []
      const maxVisible = 5
      let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
      let end = Math.min(totalPages.value, start + maxVisible - 1)
      
      if (end - start + 1 < maxVisible) {
        start = Math.max(1, end - maxVisible + 1)
      }
      
      for (let i = start; i <= end; i++) {
        pages.push(i)
      }
      
      return pages
    })
    
    const availableParentCategories = computed(() => {
      if (!isEditing.value) return categories.value
      
      // 编辑时，排除自己和自己的子分类
      return categories.value.filter(category => {
        if (category.categoryId === categoryForm.categoryId) return false
        if (category.parentId === categoryForm.categoryId) return false
        return true
      })
    })
    
    const isFormValid = computed(() => {
      return categoryForm.categoryName.trim().length >= 2 && !errors.categoryName
    })
    
    // 方法
    const loadCategories = async () => {
      loading.value = true
      try {
        const response = await categoryAPI.getAllCategories()
        if (response.success) {
          categories.value = response.categories
        } else {
          console.error('加载分类列表失败:', response.message)
        }
      } catch (error) {
        console.error('加载分类列表错误:', error)
      } finally {
        loading.value = false
      }
    }

    const refreshCategories = () => {
      loadCategories()
    }
    
    const clearSearch = () => {
      searchQuery.value = ''
      currentPage.value = 1
    }
    
    const goToPage = (page) => {
      if (page >= 1 && page <= totalPages.value) {
        currentPage.value = page
      }
    }
    
    const getCategoryName = (categoryId) => {
      const category = categories.value.find(c => c.categoryId === categoryId)
      return category ? category.categoryName : '未知分类'
    }
    
    const showAddModal = () => {
      resetForm()
      isEditing.value = false
      showCategoryModal.value = true
    }
    
    const editCategory = (category) => {
      categoryForm.categoryId = category.categoryId
      categoryForm.categoryName = category.categoryName
      categoryForm.parentId = category.parentId || ''
      categoryForm.description = category.description || ''
      
      isEditing.value = true
      showCategoryModal.value = true
    }
    
    const closeCategoryModal = () => {
      showCategoryModal.value = false
      resetForm()
    }
    
    const resetForm = () => {
      categoryForm.categoryId = null
      categoryForm.categoryName = ''
      categoryForm.parentId = ''
      categoryForm.description = ''
      errors.categoryName = ''
    }
    
    const validateCategoryName = () => {
      if (!categoryForm.categoryName.trim()) {
        errors.categoryName = '请输入分类名称'
      } else if (categoryForm.categoryName.trim().length < 2) {
        errors.categoryName = '分类名称至少2个字符'
      } else {
        errors.categoryName = ''
      }
    }
    
    const handleSubmit = async () => {
      validateCategoryName()
      
      if (!isFormValid.value) return
      
      submitting.value = true
      
      try {
        const data = {
          categoryName: categoryForm.categoryName.trim(),
          parentId: categoryForm.parentId || null,
          description: categoryForm.description.trim() || null
        }
        
        let response
        if (isEditing.value) {
          data.categoryId = categoryForm.categoryId
          response = await categoryAPI.updateCategory(categoryForm.categoryId, data)
        } else {
          response = await categoryAPI.addCategory(data)
        }
        
        if (response.success) {
          closeCategoryModal()
          await loadCategories()
        } else {
          alert(response.message || (isEditing.value ? '更新分类失败' : '添加分类失败'))
        }
      } catch (error) {
        console.error('提交分类数据错误:', error)
        alert(isEditing.value ? '更新分类失败，请检查网络连接' : '添加分类失败，请检查网络连接')
      } finally {
        submitting.value = false
      }
    }
    
    const confirmDeleteCategory = (category) => {
      categoryToDelete.value = category
      showDeleteModal.value = true
    }
    
    const deleteCategory = async () => {
      if (!categoryToDelete.value) return
      
      deletingCategoryId.value = categoryToDelete.value.categoryId
      
      try {
        const response = await categoryAPI.deleteCategory(categoryToDelete.value.categoryId)
        if (response.success) {
          showDeleteModal.value = false
          await loadCategories()
        } else {
          alert(response.message || '删除分类失败')
        }
      } catch (error) {
        console.error('删除分类错误:', error)
        alert('删除分类失败，请检查网络连接')
      } finally {
        deletingCategoryId.value = null
        categoryToDelete.value = null
      }
    }
    
    const formatDate = (date) => {
      if (!date) return '-'
      return new Date(date).toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit'
      })
    }
    
    const toggleSelectAll = () => {
      isAllSelected.value = !isAllSelected.value
      selectedCategories.value = isAllSelected.value ? categories.value.map(c => c.categoryId) : []
    }
    
    const batchDeleteCategories = async () => {
      if (selectedCategories.value.length === 0) return
      
      try {
        const response = await categoryAPI.deleteCategories(selectedCategories.value)
        if (response.success) {
          selectedCategories.value = []
          await loadCategories()
        } else {
          alert(response.message || '批量删除分类失败')
        }
      } catch (error) {
        console.error('批量删除分类错误:', error)
        alert('批量删除分类失败，请检查网络连接')
      }
    }
    
    // 监听搜索变化，重置页码
    watch(searchQuery, () => {
      currentPage.value = 1
    })

    // 点击外部关闭批量操作菜单
    const handleClickOutside = (event) => {
      if (!event.target.closest('.floating-batch-actions')) {
        showBatchMenu.value = false
      }
    }

    // 生命周期
    onMounted(() => {
      loadCategories()
      document.addEventListener('click', handleClickOutside)
    })

    return {
      categories,
      loading,
      searchQuery,
      currentPage,
      pageSize,
      showCategoryModal,
      showDeleteModal,
      isEditing,
      submitting,
      deletingCategoryId,
      categoryToDelete,
      categoryForm,
      errors,
      filteredCategories,
      totalPages,
      paginatedCategories,
      visiblePages,
      availableParentCategories,
      isFormValid,
      loadCategories,
      refreshCategories,
      clearSearch,
      goToPage,
      getCategoryName,
      showAddModal,
      editCategory,
      closeCategoryModal,
      validateCategoryName,
      handleSubmit,
      confirmDeleteCategory,
      deleteCategory,
      formatDate,
      selectedCategories,
      isAllSelected,
      toggleSelectAll,
      batchDeleteCategories,
      showBatchMenu
    }
  }
}
</script>

<style scoped>
.category-management {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* 页面头部 */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: white;
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-content h1 {
  margin: 0 0 8px 0;
  color: #2c3e50;
  font-size: 24px;
  font-weight: 600;
}

.page-description {
  margin: 0;
  color: #7f8c8d;
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* 搜索区域 */
.search-section {
  background: white;
  padding: 20px 24px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.search-input-wrapper {
  position: relative;
  max-width: 400px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #7f8c8d;
  font-size: 14px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.clear-search {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #7f8c8d;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.3s ease;
}

.clear-search:hover {
  color: #e74c3c;
}

/* 分类列表 */
.categories-section {
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #7f8c8d;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #ecf0f1;
  border-top: 3px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #7f8c8d;
}

.empty-state i {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  margin: 0 0 8px 0;
  color: #2c3e50;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

/* 表格样式 */
.categories-table-container {
  overflow-x: auto;
}

.categories-table {
  width: 100%;
  border-collapse: collapse;
}

.categories-table th {
  background: #f8f9fa;
  padding: 16px 20px;
  text-align: left;
  font-weight: 600;
  color: #2c3e50;
  font-size: 14px;
  border-bottom: 1px solid #e1e5e9;
}

.categories-table td {
  padding: 16px 20px;
  border-bottom: 1px solid #f1f3f4;
  vertical-align: middle;
}

.category-row:hover {
  background: #f8f9fa;
}

.category-info-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #f093fb, #f5576c);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
}

.category-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.category-name {
  font-weight: 500;
  color: #2c3e50;
  font-size: 14px;
}

.category-id {
  font-size: 12px;
  color: #7f8c8d;
}

.parent-cell {
  font-size: 13px;
  color: #5a6c7d;
}

.no-parent {
  color: #7f8c8d;
  font-style: italic;
}

.description-cell {
  max-width: 200px;
}

.description-text {
  font-size: 13px;
  color: #5a6c7d;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.date-cell {
  font-size: 13px;
  color: #5a6c7d;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

/* 分页 */
.pagination-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-top: 1px solid #e1e5e9;
}

.pagination-info {
  font-size: 14px;
  color: #7f8c8d;
}

.pagination-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-numbers {
  display: flex;
  gap: 4px;
}

/* 按钮样式 */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #3498db;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #2980b9;
}

.btn-secondary {
  background: #ecf0f1;
  color: #7f8c8d;
}

.btn-secondary:hover:not(:disabled) {
  background: #d5dbdb;
}

.btn-success {
  background: #28a745;
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #218838;
}

.btn-info {
  background: #17a2b8;
  color: white;
}

.btn-info:hover:not(:disabled) {
  background: #138496;
}

.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #c82333;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: white;
  border-radius: 16px;
  width: 500px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  border-bottom: 1px solid #e1e5e9;
}

.modal-header h3 {
  margin: 0;
  color: #2c3e50;
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #7f8c8d;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.3s ease;
}

.modal-close:hover {
  color: #e74c3c;
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #2c3e50;
  font-size: 14px;
}

.required {
  color: #e74c3c;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e1e5e9;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.3s ease;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-input.error {
  border-color: #e74c3c;
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.error-text {
  color: #e74c3c;
  font-size: 12px;
  margin-top: 4px;
  display: block;
}

.warning-text {
  color: #e67e22;
  font-size: 14px;
  margin: 8px 0 0 0;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 24px;
  border-top: 1px solid #e1e5e9;
}

/* 悬浮批量操作按钮 */
.floating-batch-actions {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  border: 1px solid #e9ecef;
  overflow: hidden;
  transition: all 0.3s ease;
}

.batch-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}

.batch-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.selected-count {
  font-size: 18px;
  font-weight: 700;
  color: #3498db;
  background: #ecf4fd;
  padding: 4px 8px;
  border-radius: 8px;
  min-width: 28px;
  text-align: center;
}

.selected-text {
  font-size: 14px;
  color: #7f8c8d;
  font-weight: 500;
}

.batch-buttons {
  position: relative;
}

.batch-toggle-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #3498db;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.3s ease;
}

.batch-toggle-btn:hover {
  background: #2980b9;
  transform: scale(1.05);
}

.batch-toggle-btn.active {
  background: #e74c3c;
  transform: rotate(90deg);
}

.batch-menu {
  border-top: 1px solid #f1f3f4;
  background: #fafbfc;
}

.batch-menu-header {
  padding: 12px 20px;
  border-bottom: 1px solid #f1f3f4;
  background: #ffffff;
}

.batch-menu-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
}

.batch-menu-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 20px;
}

.batch-action-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-label {
  font-size: 12px;
  font-weight: 600;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .search-input-wrapper {
    max-width: none;
  }
  
  .categories-table th,
  .categories-table td {
    padding: 12px 16px;
  }
  
  .description-cell {
    max-width: 150px;
  }
  
  .pagination-container {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .pagination-controls {
    justify-content: center;
  }
  
  .modal-content {
    width: 95vw;
    margin: 20px;
  }
}
</style> 